try:
    import efl.evas as evas
    import efl.ecore as ecore
    import efl.edje as edje
    import efl.elementary as elm
    from efl.elementary import ELM_POLICY_QUIT, \
        ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
    from efl.elementary.window import Window, StandardWindow, ELM_WIN_BASIC, \
        ELM_WIN_DIALOG_BASIC
    from efl.elementary.background import Background
    from efl.elementary.box import Box
    from efl.elementary.label import Label
    from efl.elementary.naviframe import Naviframe
    from efl.elementary.popup import Popup
    from efl.elementary.button import Button
    from efl.elementary.scroller import Scroller, ELM_SCROLLER_POLICY_OFF, \
        ELM_SCROLLER_POLICY_AUTO
    from efl.elementary.check import Check
    from efl.elementary.progressbar import Progressbar
    from efl.elementary.genlist import Genlist, GenlistItemClass
    from efl.elementary.segment_control import SegmentControl
    from efl.elementary.frame import Frame
    from efl.elementary.entry import Entry
    from efl.elementary.icon import Icon
    from efl.elementary.layout import Layout
    from efl.elementary.theme import Theme
except:
    import elementary as elm
    import evas, e_dbus, ecore, edje
    from e_dbus import DBusEcoreMainLoop
    from elementary import Window, Background, Box, Label, Naviframe, Popup, \
        Button, Scroller, Check, Progressbar, Genlist, GenlistItemClass, \
        SegmentControl, Frame, Entry, Icon, Layout, Theme, ELM_WIN_BASIC, \
        ELM_WIN_DIALOG_BASIC, ELM_POLICY_QUIT, ELM_SCROLLER_POLICY_OFF, \
        ELM_SCROLLER_POLICY_AUTO, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED

EXPAND_BOTH = (evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
EXPAND_HORIZ = (evas.EVAS_HINT_EXPAND, 0.0)
FILL_BOTH = (evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)

def _deleted(obj):
    log.debug("View deleted %s (%s)", self.__class__.__name__, self.path)
    self.sig_ch.remove()
    self.sig_ch = None
    self.obj = None

def create_view(properties):
    log.critical("must be implemented!")
    pass

def on_property_changed(name, value):
    log.critical("must be implemented!")

def add_check(box, label, callback=None):
    obj = Check(box)
    obj.size_hint_weight = EXPAND_HORIZ
    obj.size_hint_align = FILL_BOTH
    obj.text = label
    obj.show()
    box.pack_end(obj)
    if callback:
        obj.callback_changed_add(callback)
    return obj

def add_bt_box(box, label, callback):
    obj = Button(box)
    obj.size_hint_weight = EXPAND_HORIZ
    obj.size_hint_align = FILL_BOTH
    obj.text = label
    obj.show()
    obj.callback_clicked_add(callback)
    box.pack_end(obj)
    return obj
    
def add_box(win):
    box= Box (win)
    box.size_hint_weight = EXPAND_HORIZ
    box.size_hint_align = FILL_BOTH
    #box.horizontal= True
    #box.homogeneuos= True
             
    box.show()
    return box

def add_bt_naviframe (label, callback, nf):
    obj = Button(nf, text= label)
    obj.size_hint_weight = EXPAND_HORIZ
    obj.size_hint_align = FILL_BOTH
    obj.callback_clicked_add(callback, nf)
    nf.item_push(label, bt, bt2, content, "overlap")
    return obj

def add_label(box, label):
    lb = Label(box)
    lb.size_hint_weight = EXPAND_HORIZ
    lb.size_hint_align = FILL_BOTH
    lb.text = label
    lb.show()
    box.pack_end(lb)
    return lb

def add_progress(box, label):
    pb = Progressbar(box)
    pb.size_hint_weight = EXPAND_HORIZ
    pb.size_hint_align = FILL_BOTH
    pb.text = label
    pb.show()
    box.pack_end(pb)
    return pb

#def add_segment_control(box, options, callback):
    #sc = SegmentControl(box)
    #sc.size_hint_weight = EXPAND_HORIZ
    #sc.size_hint_align = FILL_BOTH
    #items = {}
    #for o in options:
        #items[o] = sc.item_add(None, o)
    #sc.show()
    #box.pack_end(sc)
    #sc.callback_changed_add(callback)
    #return sc, items

def add_frame_and_box(box, label):
    fr = Frame(box)
    fr.size_hint_weight = EXPAND_BOTH
    fr.size_hint_align = FILL_BOTH
    fr.text = label
    fr.show()
    box.pack_end(fr)

    bx = Box(fr)
    bx.size_hint_weight = EXPAND_BOTH
    bx.size_hint_align = FILL_BOTH
    #bx.horizontal = False
    bx.show()
    fr.content = bx
    return fr, bx

def add_label_and_entry(box, label, callback=None):
    lb = self.add_label(box, label)

    en = Entry(box)
    en.size_hint_weight = EXPAND_HORIZ
    en.size_hint_align = FILL_BOTH
    en.single_line = True
    en.scrollable = True
    en.show()
    box.pack_end(en)
    if callback:
        en.callback_activated_add(callback)
    return lb, en
    
class WindowPrim(evas.Object):
    def __init__ (self, frame, label):
        self.viewBox= add_box (frame)
        self.init_view(frame, label)

    def show_view (self, bt, box):
        print (box.children)
        box.hide()
        box.unpack_all()
        box.pack_end (self.viewBox)
        self.viewBox.show()

    def init_view (self, frame, label):
        self.viewBox.pack_start(add_label(self.viewBox, label))
        self.viewBox.hide()
